import './style.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import DataVVue3 from '@kjgl77/datav-vue3'
import '@kjgl77/datav-vue3/dist/style.css'
import request from '@/utils/request'
import {
  BorderBox1,
  BorderBox13,
  Decoration3
} from '@kjgl77/datav-vue3'

import App from './App.vue'
import router from './router'
import axios from 'axios'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import { ElMessage } from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App)

app.config.globalProperties.$request = request

app.use(createPinia())
app.use(router)
app.use(DataVVue3)
app.use(BorderBox1)
app.use(BorderBox13)
app.use(Decoration3)
app.use(ElementPlus)

// 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 设置全局的请求拦截器
axios.interceptors.request.use(config => {
  const token = localStorage.getItem('token')
  if (token) {
    config.headers['Authorization'] = `Bearer ${token}`
  }
  return config
})

app.mount('#app')
